﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.services.*;

    public class PostOnWallCommand extends Command {

        public var event:InfoEvent;
        public var environmentModel:EnvironmentModel;
        public var sessionModel:SessionModel;
        public var languageModel:LanguageModel;
        public var fileInfoModel:FileInfoModel;
        public var userModel:UserModel;
        public var friendsModel:FriendsModel;
        public var extInterface:ExtInterfaceService;

        override public function execute():void{
            switch (this.event.info.type){
                case GameConstants.POST_LEVEL_UP:
                    this.onLevelUp();
                    break;
                case GameConstants.ASK_FOR_SYMBOL:
                    this.onAskForSymbol();
                    break;
                case GameConstants.POST_NEW_DISEASE:
                    this.onNewDisease();
                    break;
                case GameConstants.POST_FIRST_CURED:
                    this.onFirstTimeCured();
                    break;
                case GameConstants.POST_HAPPY_FAMILY:
                    this.onHappyFamily();
                    break;
                case GameConstants.MISSION_SOLVED:
                    this.onMissionSolved();
                    break;
                case GameConstants.REGENERATION_FINALIZED:
                    this.onRegenerationFinalized();
                    break;
                case GameConstants.STOLEN_GEM:
                    this.onStolenGem();
                    break;
                case GameConstants.POST_ACHIEVEMENT:
                    this.onAchievement();
                    break;
            };
        }
        private function onAchievement():void{
            l("onAchievement");
            var _local1:RewardVO = RewardVO(this.event.info.vo);
            var _local2:AchievementVO = _local1.achievementVO;
            var _local3:String = this.getAppURL(("m" + _local1.id));
            var _local4:Array = [this.image((("achievements/" + _local1.id) + ".png"), _local3)];
            var _local5:String = this.text(("pow_achievement_" + _local2.id), {medal:this.text(("achievement_" + _local1.medal)), amount:_local1.pointsNeeded});
            var _local6:String = this.text("pow_achievement_storybody");
            var _local7:String = this.text("pow_achievement_usermessage");
            var _local8:Object = this.getAttachment(_local5, _local6, _local3, _local4);
            var _local9:Array = [this.link("pow_achievement_actionlink", _local3)];
            this.postOnWall(_local8, _local9, null, _local7, _local1.id, ("m" + _local1.id));
        }
        private function onStolenGem():void{
            var _local1:String = this.event.info.id;
            var _local2:String = this.userModel.visitingFriendID;
            var _local3:String = this.getAppURL(_local2);
            var _local4:Array = [this.image((("stolen_gem/POW_stealgem_" + _local1) + ".png"), _local3)];
            var _local5:String = this.text((("pow_stealgem_" + _local1) + "_storytitle"), this.event.info);
            var _local6:String = this.text((("pow_stealgem_" + _local1) + "_storybody"), this.event.info);
            var _local7:Object = this.getAttachment(_local5, _local6, _local3, _local4);
            var _local8:Array = [this.link(this.event.info.link, _local3)];
            var _local9:String = this.text("pow_stealgem_usermessage", this.event.info);
            this.postOnWall(_local7, _local8, _local2, _local9, _local2, null);
        }
        private function onRegenerationFinalized():void{
            var _local1:String = this.event.info.patientId;
            var _local2:String = this.event.info.patientType.toLowerCase();
            var _local3:String = this.getAppURL(("e" + _local1));
            var _local4:Array = [this.image((("fountain/" + _local2) + "_baby_fountain.png"), _local3)];
            var _local5:String = this.text("fountain_cured_storytitle");
            var _local6:String = this.text("fountain_cured_storybody");
            var _local7:Object = this.getAttachment(_local5, _local6, _local3, _local4);
            var _local8:Array = [this.link("fountain_cured_actionlink", _local3)];
            this.postOnWall(_local7, _local8, null, this.text("fountain_cured_usermessage"), _local1, ("e" + _local1));
        }
        private function onAskForSymbol():void{
            var _local1:String = this.event.info.symbol;
            var _local2:String = ((("s" + _local1) + "-") + new Date().time);
            var _local3:String = this.getAppURL(_local2);
            var _local4:Array = [this.image((("fountain/" + _local1) + "_pow.png"), _local3)];
            var _local5:Object = {symbol:("fountain_symbol_" + _local1)};
            var _local6:String = this.text("fountain_ask_for_symbol_storytitle", _local5);
            var _local7:String = this.text("fountain_ask_for_symbol_storybody", _local5);
            var _local8:Object = this.getAttachment(_local6, _local7, _local3, _local4);
            var _local9:Array = [this.link("fountain_ask_for_symbol_actionlink", _local3)];
            this.postOnWall(_local8, _local9, null, this.text("fountain_ask_for_symbol_usermessage"), _local2, _local2, _local1);
        }
        private function onMissionSolved():void{
            var _local1:String = this.event.info.code;
            var _local2:String = this.getAppURL(_local1);
            var _local3:Array = [this.image((("mission_solved/pow_mission_graphic_" + _local1) + ".png"), _local2)];
            var _local4:String = this.text((("pow_mission_" + _local1) + "_storytitle"), {disease:this.event.info.disease_name});
            var _local5:Object = this.getAttachment(_local4, (("pow_mission_" + _local1) + "_storybody"), _local2, _local3);
            var _local6:Array = [this.link((("pow_mission_" + _local1) + "_actionlink"), _local2)];
            this.postOnWall(_local5, _local6, null, this.text((("pow_mission_" + _local1) + "_usermessage")), _local1, _local1);
        }
        private function onFirstTimeCured():void{
            var _local1:String = ITreatable(this.event.info.pet).diseaseId.toString();
            var _local2:String = this.getAppURL(("c" + _local1));
            var _local3:Array = [this.image((("first_time_finished/" + this.event.info.disease_id) + ".png"), _local2)];
            var _local4:String = this.text("pow_1stCured_storytitle", {disease:this.event.info.disease_name});
            var _local5:Object = this.getAttachment(_local4, "pow_1stCured_storybody", _local2, _local3);
            var _local6:Array = [this.link("pow_1stCured_actionlink", _local2)];
            this.postOnWall(_local5, _local6, null, this.text("pow_1stCured_usermessage"), _local1, ("c" + _local1));
        }
        private function onHappyFamily():void{
            var _local1:BabyVO = BabyVO(this.event.info.data);
            var _local2:String = _local1.type;
            var _local3:String = this.getAppURL(("f" + _local1.type));
            var _local4:Array = [this.image((("happy_family/happyfamily_" + _local1.type.toLowerCase()) + ".png"), _local3)];
            var _local5:String = this.text(this.getHappyFamilyTitle(_local1));
            var _local6:Object = this.getAttachment(_local5, "pow_happy_family_storybody", _local3, _local4);
            var _local7:Array = [this.link("pow_happy_family_actionlink", _local3)];
            this.postOnWall(_local6, _local7, null, this.text("pow_happy_family_usermessage"), _local2, ("f" + _local2));
        }
        private function getHappyFamilyTitle(_arg1:BabyVO):String{
            var _local2:String = this.getFriendNameByID(_arg1.dadId, "father");
            var _local3:String = this.getFriendNameByID(_arg1.momId, "mother");
            var _local4:String = this.languageModel.getTextByKey("pow_happy_family_storytitle", {godmother:_local3, godfather:_local2});
            return (_local4);
        }
        private function getFriendNameByID(_arg1:String, _arg2:String):String{
            if (_arg1 == GameConstants.KARLA_FACEBOOK_ID){
                return (this.languageModel.getTextByKey(("kindergarten_god" + _arg2)));
            };
            var _local3:int;
            while (_local3 < this.friendsModel.friends.length) {
                if (this.friendsModel.friends[_local3].uid == _arg1){
                    return (this.friendsModel.friends[_local3].first_name);
                };
                _local3++;
            };
            log("e no parent name found");
            return (null);
        }
        private function onNewDisease():void{
            var _local1:String = ITreatable(this.event.info.pet).diseaseId.toString();
            var _local2:String = this.getAppURL(("d" + _local1));
            var _local3:Array = [this.image((("new_disease/" + this.event.info.disease_id) + ".png"), _local2)];
            var _local4:String = this.text("pow_1stTreatment_storytitle", {disease:this.event.info.disease_name});
            var _local5:Object = this.getAttachment(_local4, "pow_1stTreatment_storybody", _local2, _local3);
            var _local6:Array = [this.link("pow_1stTreatment_actionlink", _local2)];
            this.postOnWall(_local5, _local6, null, this.text("pow_1stTreatment_usermessage"), _local1, ("d" + _local1));
        }
        private function onLevelUp():void{
            var _local1:String = this.userModel.level.toString();
            var _local2:String = this.getAppURL(("l" + _local1));
            var _local3:Array = [this.image("level_up/LevelUp.png", _local2)];
            var _local4:String = this.text("pow_levelup_storytitle", {level:_local1});
            var _local5:Object = this.getAttachment(_local4, "pow_levelup_storybody", _local2, _local3);
            var _local6:Array = [this.link("pow_levelup_actionlink", _local2)];
            this.postOnWall(_local5, _local6, null, this.text("pow_levelup_usermessage"), _local1, ("l" + _local1));
        }
        private function postOnWall(_arg1:Object, _arg2:Array, _arg3:String, _arg4:String, _arg5:String, _arg6:String=null, _arg7:String=null):void{
            _arg6 = (_arg6) ? (((this.environmentModel.main_service_url + this.sessionModel.session_id) + "/feed_post/create?item_id=") + _arg6) : null;
            var _local8:Object = {sender_id:this.userModel.mySocialID, feed_type:this.event.info.type, feed_id:_arg5, language:this.environmentModel.locale, success_url:_arg6, optional_type:_arg7};
            this.extInterface.callJS("postOnWall", ["", _arg1, _arg2, _arg3, _arg4, _local8]);
        }
        private function getAttachment(_arg1:String, _arg2:String, _arg3:String, _arg4:Array):Object{
            var _local5:Object = {};
            _local5.name = this.languageModel.getTextByKey("global_text", {text:_arg1});
            _local5.description = this.languageModel.getTextByKey("global_text", {text:_arg2});
            _local5.href = _arg3;
            _local5.media = _arg4;
            return (_local5);
        }
        private function image(_arg1:String, _arg2:String):Object{
            _arg1 = ((GameConstants.ASSETS_PATH + "locale/all/feedposts/") + _arg1);
            _arg1 = this.fileInfoModel.getCdnUrl(_arg1);
            return ({type:"image", src:_arg1, href:_arg2});
        }
        private function text(_arg1:String, _arg2:Object=null):String{
            return (this.languageModel.getTextByKey(_arg1, _arg2));
        }
        private function link(_arg1:String, _arg2:String):Object{
            return ({text:this.languageModel.getTextByKey(_arg1), href:_arg2});
        }
        private function getAppURL(_arg1:String):String{
            return (((((((this.environmentModel.facebookUrl + "feed_post/accept?ref=nf&w_sender=") + this.userModel.mySocialID) + "&w_accept=") + _arg1) + "&st1=") + _arg1));
        }

    }
}//package net.wooga.pets.controllers 
